<div class="cms_browse_heading">
	<div class="cms_browse_heading_label">
		<h1>View Image</h1>
	</div>
</div>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>
<div id="cms_browse">	
<?

	$documentCode = extractNumberWithKeyFromArray('documentCode', $_REQUEST);
	$folder = extractNumberWithKeyFromArray('folder', $_REQUEST);
	$parent = extractNumberWithKeyFromArray('parent', $_REQUEST);
	$document = $cmsDocument->openDocument($documentCode);
	
	if (!is_null($document) && $document->formid == 130){
		
		$documentDetails = getFileDetails($document, $db );
		if (is_null($documentDetails)) {
			$documentDetails = new stdClass();//create this to pad out the bollocks
			$documentDetails->filename = "NO IMAGE DATA FOUND";
			$documentDetails->filesize = 0;
			$documentDetails->id  = 0;
		}
		
		$documentCaption = magicClean($document->title);			
		$documentDate = magicClean($document->documentdate);
		
		$documentFilename = magicClean($documentDetails->filename);

		$returnURL = $_SERVER['PHP_SELF'] . "?fileNo=1&formid=130&sorts=clear&direction=clear&folder=$folder&parent=$parent";		
		$cancelURL = $_SERVER['PHP_SELF'] . "?fileNo=101&documentCode=". $documentCode . "&folder=" . $folder ."&parent=$parent";		
		
		$editUrl = $_SERVER['PHP_SELF'] . '?fileNo=2&documentCode=' . $document->documentcode . "&returnURL=" . urlencode($cancelURL);
		$deleteUrl = $_SERVER['PHP_SELF'] . '?fileNo=4&documentCode=' . $document->documentcode . "&returnURLEncoded=" . urlencode( $returnURL ) . "&cancelURLEncoded=" . urlencode( $cancelURL );
	
		if ($documentDetails->id === 0 ) {
			$imageUrl = '/cms/html/files/images/icon_imgbroken_lrg.gif';
			$downloadUrl = null;
		} else  {
			$imageUrl = '/html/blob.php?attach=false&documentCode=' . $document->documentcode . '&scale=1&width=300';
			$downloadUrl = '/html/blob.php?attach=true&documentCode=' . $document->documentcode ;
		}
		
			print <<< EOD
    <TABLE cellSpacing="0" cellPadding="0" width="560" border="0">
          <TR>
 		    <TD width="240" align="left" valign="top" class="cms_browsetext"><b>$documentFilename</b><br/>
              <br />
              $documentCaption<br />
              <br />
              <br />
EOD;
			if ($documentDetails->id !== 0) {
				print <<< EOD
              <img src="/cms/html/files/images/icon_imglist.gif" width="35" height="20" align="left" />
              	<a href="$downloadUrl">Download/Save image</a><br />
              <i>($documentDetails->filesize bytes)<br />
EOD;
			}          
			print <<< EOD
        <br>
              <img height="7" src="/cms/images/greyline.gif" width="230" /><br />
              Date added:$documentDate<br />
              Document Code: $document->documentcode<br />
              File Id: $documentDetails->id </i>
			  <img height="7" src="/cms/images/greyline.gif" width="230" /><br />
              <a href="$editUrl">Edit</a> / <a href="$deleteUrl">Delete</a>
		   </TD>
 		   <TD width="320" style="vertical-align:top;">
			<div class="wrap1" style="float: right">
 				 <div class="wrap2">		          
                  <div class="wrap3"><img src="$imageUrl" alt="description" border="0" /></div>
				 </div>
			</div>
			</TD>
		</TR>
		<tr>
			<td colspan="2">
			  Small Url: <a target="_blank" href="/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=100">/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=100</a><br />
              Medium Url: <a target="_blank" href="/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=300">/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=300</a><br />
              Large Url: <a target="_blank" href="/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=600">/html/blob.php?attach=false&documentCode=$document->documentcode&scale=1&width=600</a><br />
			</td>
		</tr>
	</TABLE>
EOD;
		} else {
			echo "FILE NOT FOUND";
		}


	
	
	$upUrl = $_SERVER['PHP_SELF'] . "?fileNo=1&formid=$formid&parent=$parent&folder=" . $folder ;
?></div>
<table cellpadding="0" cellspacing="0" width="100%" border="0">
                    <TR> 
                      <TD align="left" colSpan="3"><IMG height="7" src="/cms/images/greyline.gif" width="100%" /></TD>
                    </TR>
                    
                    <TR> 
                      <TD class="cms_browsetext" width="35"><a href="<?= $upUrl ?>"><img src="/cms/html/files/images/icon_folderup.gif" width="35" height="20" /></a></TD>
                      <TD class="cms_browsetext" width="300"><a href="<?= $upUrl ?>"><i>.. Back to image folder.</i></a></TD>
                      <TD width="1"><IMG height="20" src="/cms/images/spacer.gif" width="1" /></TD>
					</tr>

					<TR> 
                      <TD align="left" colSpan="3"><IMG height="7" src="/cms/images/greyline.gif" width="100%" /></TD>
                    </TR>
</table>
